<?php

/*
function isCheckCashingPictureExist
*/
function isCheckCashingPictureExist( $filename )
{
	

	if(( is_file(PATH_CHECKCASHINGIMAGES . $filename))&& ( is_file(PATH_CHECKCASHINGIMAGES_THUMB_240x174 . $filename)) ) 
		{
			
			return true;
		}
	//elseif ((is_file(PATH_CHECKCASHINGIMAGES . $filename)) && ( is_file(PATH_CHECKCASHINGIMAGES_THUMB_428x294 . $filename))
//				&& ( is_file(PATH_CHECKCASHINGIMAGES_THUMB_240x174 . $filename))) {
//		return true;
//	}
	else {
		return false;
	}
	
	
}

/*
function returnCheckCashingPictureName
	Input: cust no, Comp no, type = CUSTOMER or COMPANY
	Out put: file name of picture
*/
function returnCheckCashingPictureName($type = '',$Cust_no = '', $Comp_no = '',$store='' )
{
	
	if ($Cust_no == '')
	{
		return DEFAULT_CHECKCASHINGPICTURE_IMAGE;
	}
	
	switch ($type)
	{
		case 'COMPANY':
		
			$sFile_1 = $store . '/' .$Cust_no . ' ' . $Comp_no . '.jpg';
			$sFile_2 = $store . '/' .$Cust_no . ' ' . $Comp_no . '.JPG';			
			break;
		case 'CUSTOMER':
	
			$sFile_1 = $store . '/' .$Cust_no . '.jpg';
			$sFile_2 = $store . '/' .$Cust_no . '.JPG';
			
			break;
		default:
			return DEFAULT_CHECKCASHINGPICTURE_IMAGE;
	} 
	if (isCheckCashingPictureExist($sFile_1)) 
	{
		return $sFile_1;
	}
	elseif (isCheckCashingPictureExist($sFile_2))
	{
		return $sFile_2;
	}
	else{
		return DEFAULT_CHECKCASHINGPICTURE_IMAGE;
	}

	
}

/*
Copy Directory
@param:
	- fromDir: Directory Source
	- toDir: Directory Destination
*/
function copyDir($fromDir, $toDir){
	global $upload_directory_mod;
	global $upload_file_mod;
	
	$success = true;
	$handle = opendir($fromDir);
	
	//ensure target directory exists
	if(!file_exists($toDir)) 
		if(mkdir($toDir))
			chmod($toDir, octdec($upload_directory_mod));
		else
			return false;
	
	while(false !== ($item = readdir($handle)))
		if($item != '.' && $item != '..') {
			$from = $fromDir.'/'.$item;
			$to = $toDir.'/'.$item;
			
			if(is_dir($from)) {
				if($success &= mkdir($to))
					chmod($to, octdec($upload_directory_mod));
			  //recurse
			  copyDir($from, $to);
			} else {
				if($success &= copy($from, $to))
					chmod($to, octdec($upload_file_mod));
			}
		}
	closedir($handle);
	
	return $success;
}
/*
Delete Directory
*/
function  delete_directory($dirname)  {
	if  (is_dir($dirname))
		$dir_handle  =  opendir($dirname);
	if  (!$dir_handle)
		return  false;
	while($entry  =  readdir($dir_handle))  {
		if  ($entry  !=  "."  &&  $entry  !=  "..")  {
			if  (!is_dir($dirname."/".$entry))
				unlink($dirname."/".$entry);
			else
				delete_directory($dirname.'/'.$entry);                       
		}
	}
	closedir($dir_handle);
	rmdir($dirname);
	return  true;
} 
/**/
function deletefile($file_name){
	global $rootPath;
	$src_path = $rootPath.$file_name;
	if (file_exists($src_path)) { 
		$deleted = unlink($src_path);
	}
	return $deleted;
}


?>